In [8]:
%load_ext autoreload
%autoreload 2
import etherscan.accounts as accounts
import json


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

Import our api_key

The JSON keyfile being read in has only one line in the format:

{"key" : "YourApiKey" }

In [15]:
with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

Setup api for single address


In [16]:
address = '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b'
api = accounts.Account(address=address, api_key=key)

Get the balance


In [17]:
api.get_balance()


Out[17]:
'1416845749966260146664'

Collect transactions


In [26]:
api.get_transaction_page(page=1, offset=10)


Out[26]:
[{'blockHash': '0x866595af1d2db58574c6ce73d77a965db53f0ed882714060405f737285837583',
  'blockNumber': '80055',
  'confirmations': '1695998',
  'contractAddress': '',
  'cumulativeGasUsed': '85575',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '90000',
  'gasPrice': '55098633173',
  'gasUsed': '21000',
  'hash': '0xcff7bab07a096e4c01dd6a76befb2c0b11ebeec5bbb38b592f6daaa755ba60b6',
  'input': '0x',
  'isError': '0',
  'nonce': '0',
  'timeStamp': '1439479435',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '2',
  'value': '95000000000000000000'},
 {'blockHash': '0xc88c09ae97eb685a52a8d7c3e82cfbf2917deac1a24fc24ec134caa001a0a4fa',
  'blockNumber': '313661',
  'confirmations': '1462392',
  'contractAddress': '',
  'cumulativeGasUsed': '21000',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '90000',
  'gasPrice': '50000000000',
  'gasUsed': '21000',
  'hash': '0x8347079dee0a85c0b643e44e37ec18d423392028c22b1caae0d642f9114b6617',
  'input': '0x',
  'isError': '0',
  'nonce': '1',
  'timeStamp': '1443641229',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '0',
  'value': '10170000000000000000'},
 {'blockHash': '0x27e09b7878e445be37758cc8ca15672cf67ea51675a8060c258b43d4b810b682',
  'blockNumber': '477938',
  'confirmations': '1298115',
  'contractAddress': '',
  'cumulativeGasUsed': '21000',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '90000',
  'gasPrice': '50000000000',
  'gasUsed': '21000',
  'hash': '0x578239b66f3119baa5783136a33f00b3bb71068e77dc4d06d3a761e8d81c6028',
  'input': '0x',
  'isError': '0',
  'nonce': '2',
  'timeStamp': '1446457828',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '0',
  'value': '20000000000000000000'},
 {'blockHash': '0x7eec9a784f21a63ce07876e535b8a9b7b6d9ef8a3a2ba5fa82d9b732084ae645',
  'blockNumber': '477942',
  'confirmations': '1298111',
  'contractAddress': '',
  'cumulativeGasUsed': '189000',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '90000',
  'gasPrice': '50000000000',
  'gasUsed': '21000',
  'hash': '0x291e0df6d7466081a636a2f9764623365892ba167b97757ea578459597027ff7',
  'input': '0x',
  'isError': '0',
  'nonce': '3',
  'timeStamp': '1446457892',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '8',
  'value': '80000000000000000000'},
 {'blockHash': '0x8ff4b0752b37ac49ca24a1d90bfce8ff8da3857e4bf8982db15037558120f9d7',
  'blockNumber': '852036',
  'confirmations': '924017',
  'contractAddress': '',
  'cumulativeGasUsed': '228382',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '90000',
  'gasPrice': '50000000000',
  'gasUsed': '21000',
  'hash': '0x8f41b9b6b966848cf85cce0e5d2ce3e381fbd5d90a5a851c398245a65bc34f21',
  'input': '0x',
  'isError': '0',
  'nonce': '4',
  'timeStamp': '1452860882',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '2',
  'value': '500000000000000000000'},
 {'blockHash': '0x8d50c06f5f3f502578cb44ce86ab9e5b6ce517571cb2e856ebce914938ff3209',
  'blockNumber': '852377',
  'confirmations': '923676',
  'contractAddress': '',
  'cumulativeGasUsed': '21000',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '90000',
  'gasPrice': '50000000000',
  'gasUsed': '21000',
  'hash': '0xf2d59f05e8b3d85c4dccf4ce3024fb2ac017e65ba77d771f799d2f519001bca1',
  'input': '0x',
  'isError': '0',
  'nonce': '5',
  'timeStamp': '1452866973',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '0',
  'value': '1331000000000000000000'},
 {'blockHash': '0xd0dcdb42d3904d40b54f306df90341b112be68983ffe89741ff75f13031b8ed4',
  'blockNumber': '1027746',
  'confirmations': '748307',
  'contractAddress': '',
  'cumulativeGasUsed': '21000',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '90000',
  'gasPrice': '50000000000',
  'gasUsed': '21000',
  'hash': '0xb826ac26b51403a3129eff371416ce0e8bc541706d91823324fda47f6f995a38',
  'input': '0x',
  'isError': '0',
  'nonce': '6',
  'timeStamp': '1455885900',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '0',
  'value': '500000000000000000'},
 {'blockHash': '0x3b2d7511f832a427f378a91e5204e54d2ee6527b0ab497c87a873ac4c5b4e9b6',
  'blockNumber': '1027845',
  'confirmations': '748208',
  'contractAddress': '',
  'cumulativeGasUsed': '21000',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '90000',
  'gasPrice': '50000000000',
  'gasUsed': '21000',
  'hash': '0x198ba99c8cff79068ed34b66ac8d2b24b6d2a6feea14321bd0d7aed3ff78da32',
  'input': '0x',
  'isError': '0',
  'nonce': '7',
  'timeStamp': '1455887518',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '0',
  'value': '45300000000000000000'},
 {'blockHash': '0x863f7035115b36710d46235c7cab3aa5dc1c1dcc4924b1270be96ca91d8e3e4f',
  'blockNumber': '1145121',
  'confirmations': '630932',
  'contractAddress': '',
  'cumulativeGasUsed': '84000',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '121000',
  'gasPrice': '20000000000',
  'gasUsed': '21000',
  'hash': '0x5c0df4a8704ea223b58d0d50b65db5472bfd8c0322fe95fd0419d682108475af',
  'input': '0x',
  'isError': '0',
  'nonce': '8',
  'timeStamp': '1457898253',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '3',
  'value': '155000000000000000000'},
 {'blockHash': '0x78a2a4537ae58e66d991e8ccdbe447078863a60b37cd3e187c2e2d8f740d29d2',
  'blockNumber': '1203404',
  'confirmations': '572649',
  'contractAddress': '',
  'cumulativeGasUsed': '21000',
  'from': '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b',
  'gas': '121000',
  'gasPrice': '20000000000',
  'gasUsed': '21000',
  'hash': '0x613ad39823b8e22ce259d4845141f87e0b53c957976037a23bc438d3bd7d5838',
  'input': '0x',
  'isError': '0',
  'nonce': '9',
  'timeStamp': '1458750498',
  'to': '0xa6bdc31c431b8f97848c9d60cbbe9660dc450eb7',
  'transactionIndex': '0',
  'value': '208000000000000000000'}]

In [27]:
trans = api.get_all_transactions()


page 1 added
Total number of transactions: 38

Collect blocks mined


In [19]:
api.get_blocks_mined_page(page=1, offset=10,)


Out[19]:
[{'blockNumber': '1761744',
  'blockReward': '5000441000000000000',
  'timeStamp': '1466757302'},
 {'blockNumber': '1712153',
  'blockReward': '5028581000000000000',
  'timeStamp': '1466044092'},
 {'blockNumber': '1712127',
  'blockReward': '5010559500000000000',
  'timeStamp': '1466043732'},
 {'blockNumber': '1711534',
  'blockReward': '5014736422000000000',
  'timeStamp': '1466034972'},
 {'blockNumber': '1710278',
  'blockReward': '5002961000000000000',
  'timeStamp': '1466016869'},
 {'blockNumber': '1710108',
  'blockReward': '5001909425000000000',
  'timeStamp': '1466014298'},
 {'blockNumber': '1704991',
  'blockReward': '5000000000000000000',
  'timeStamp': '1465941505'},
 {'blockNumber': '1704535',
  'blockReward': '5001708460000000000',
  'timeStamp': '1465935106'},
 {'blockNumber': '1704050',
  'blockReward': '5000420000000000000',
  'timeStamp': '1465928330'},
 {'blockNumber': '1703174',
  'blockReward': '5044790580000000000',
  'timeStamp': '1465915457'}]

In [22]:
blocks_mined = api.get_all_blocks_mined()


OK
page 1 added
No transactions found
Total number of blocks mined: 927

Re-initiate api for multiple addresses


In [23]:
addresses = ['0xbb9bc244d798123fde783fcc1c72d3bb8c189413', '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a']
api = accounts.Account(address=addresses, api_key=key)
api.get_balance_multiple()


Out[23]:
[{'account': '0xbb9bc244d798123fde783fcc1c72d3bb8c189413', 'balance': '1'},
 {'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
  'balance': '40807174501130000000000'}]

In [ ]: